<?php
$txtHoten=replatestring($_POST[txtHoten],false);
$txtNgaysinh=replatestring($_POST[txtNgaysinh],false);
$txtGioitinh=replatestring($_POST[txtGioitinh],false);
$txtHonnhan=replatestring($_POST[txtHonnhan],false);
$kh_id=$_POST['kh_id'];
$Kha_Id=$_POST['Kha_Id'];
if($Kha_Id==""){$Kha_Id=$kh_id;}
$phongban=replatestring($_POST[phongban],false);
$chucvu=replatestring($_POST[chucvu],false);
$thanhtich=replatestring($_POST[thanhtich],false);


$txtDiachi=replatestring($_POST[diachi],false);
$txtDienthoai=replatestring($_POST[telephone],false);
$txtDiDong=replatestring($_POST[mobile],false);
$txtFax=replatestring($_POST[fax],false);

$txtEmail=replatestring($_POST[email],false);
$txtNickChat=replatestring($_POST[nick],false);
$txtGhichu=replatestring($_POST[notes],false);

$donviquanly=$_POST['donviquanly'];
$txtNguoiquanly=$_POST['txtNguoiquanly'];

$txtNguoitao=$_SESSION['userid'];
$txtNgaytao=time();
$txtnguoisua=$_SESSION['userid'];
$txtNgaycapnhat=time();
$txtnoidung=$_POST['txtnoidung'];

$id=replatestring($_POST[id],false);
$soanh=$_POST['hdnsoanh'];
$hinhanhsp = "";
for($i=1;$i<=$soanh;$i++){
	if($i<$soanh)$hinhanhsp .= $_POST["sanpham_hinhanh".$i]."~";
	else $hinhanhsp .= $_POST["sanpham_hinhanh".$i];
}
$date=time();
$nguoiql=$_POST['nguoiql'];
$Nguoi_Quan_Ly_Khac=$_POST['Nguoi_Quan_Ly_Khac'];	
if($Nguoi_Quan_Ly_Khac==""){$Nguoi_Quan_Ly_Khac=$nguoiql;}
$data=false;
if($txtHoten!==""){$data=true;}

if($data==true){
	if($id==""){
		mysql_query("insert into daumoilienlac 
(name,birthday,sex,status,khachhang_id,room,chucvu,thanhtich,telephone,mobile,fax,nick_name,address,email,notes,manager_unit,manager,manager_other,creater,creat_time,user_edit,update_time,description,file_attach)
		value('$txtHoten','$txtNgaysinh','$txtGioitinh','$txtHonnhan','$Kha_Id','$phongban','$chucvu','$thanhtich','$txtDienthoai','$txtDiDong','$txtFax','$txtNickChat','$txtDiachi','$txtEmail','$txtGhichu','$donviquanly','$txtNguoiquanly','$Nguoi_Quan_Ly_Khac','$txtNguoitao','$date','$txtnguoisua','$date','$txtnoidung','$hinhanhsp')
		");
		
	
		$cauthongbao="Thêm thành công";
		$link=$url_main_site."system/index.php?tn=customers&kh=Dmll_list";
		thongbao($cauthongbao,$link);			

	}
	else
	{
			mysql_query("
					update daumoilienlac set 
						name='$txtHoten',
						birthday='$txtNgaysinh',
						sex='$txtGioitinh',
						status='$txtHonnhan',
						khachhang_id='$Kha_Id',
						room='$phongban',
						chucvu='$chucvu',
						thanhtich='$thanhtich',
						address='$txtDiachi',
						telephone='$txtDienthoai',
						mobile='$txtDiDong',
						fax='$txtFax',
						email='$txtEmail',
						nick_name='$txtNickChat',
						notes='$txtGhichu',	
						manager='$txtNguoiquanly',
						manager_unit='$donviquanly',
						manager='$txtNguoiquanly',
						manager_other='$Nguoi_Quan_Ly_Khac',
						user_edit='$txtnguoisua',
						update_time='$date',
						description='$txtnoidung'
					
					where id='$id'
			");
			if($hinhanhsp!="")
			{
			mysql_query("update daumoilienlac set file_attach='$hinhanhsp' where id='$id'");
			}
			$cauthongbao="Bạn đã sửa thành công";
			$link=$url_main_site."system/index.php?tn=customers&kh=Dmll_list";
			thongbao($cauthongbao,$link);	

	}
}
else
{
		$cauthongbao="Dữ liệu không hợp lệ";
		$link=$url_main_site."system/index.php?tn=customers&kh=Dmll_list";
		thongbao($cauthongbao,$link);
}
?>